package com.jerry.base.io.write;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * User: Jerry
 * Date: 2024/1/24
 * Time: 19:48
 * Description:
 */
@Slf4j
public class FileWriterUsage {

    @Test
    public void write() throws IOException {
        String filePath = "src/main/resources/io/FileWriterUsage.txt";

        char c = 'A';
        char[] chars = {'a', 'b', '啊'};
        String text = "我是一串文字，我将要被写到文件中去。";
        try (FileWriter fileWriter = new FileWriter(filePath)) {
            fileWriter.write(c);
            fileWriter.write(chars);
            fileWriter.write(chars, 0, 1);
            fileWriter.write(text);
            fileWriter.write(text, 0, 10);
        }
    }
}
